package com.qhit.dao.impl;

import com.qhit.entity.Student;
import com.qhit.entity.Teacher;
import com.qhit.util.BeanHandler;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

/**
 * TODO
 *
 * @author 村头老杨头
 * @version 1.0
 * @date 2021/9/28 15:54
 */
public class TeacherDaoImpl {
    private String driver = "com.mysql.cj.jdbc.Driver";
    private String url = "jdbc:mysql://127.0.0.1:3306/edu";
    private String username = "root";
    private String password = "123456";
    public List<Teacher> getTeacherList() throws Exception{

        //加载驱动
        Class.forName(driver);
        //创建连接
        Connection conn = DriverManager.getConnection(url, username, password);
        //SQL预处理    //改
        String sql = "select * from teacher";
        PreparedStatement ps = conn.prepareStatement(sql);
        //问号填充
//        ps.setObject(1,sno);
        //发送SQL并返回结果集
        ResultSet rs = ps.executeQuery();
        //解析        //改
        List list = BeanHandler.handler(Teacher.class, rs);
        //关闭
        rs.close();
        ps.close();
        conn.close();
        //返回
        return list;
    }
}
